package com.example.cotrller;

import com.example.pojo.PayLog;
import com.example.pojo.TableData;
import com.example.service.imp.PayLogserviceimp;
import com.example.util.OpLog;
import com.example.util.SnowFlake;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller

public class PaylogCOTRLLRT {
    /*
  支付宝记录管理控制器
     */
    @Autowired
    private PayLogserviceimp payLogserviceimp;
    /*
    支付记录查询
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableData list(@RequestParam(value = "page",defaultValue = "1") Integer pagesum, @RequestParam(value = "limit",defaultValue = "4") Integer pageSize, String pay_sn){
        PageInfo<PayLog> queryall = payLogserviceimp.queryall(pagesum, pageSize, pay_sn);
        TableData  tableData = new TableData();
        tableData.setCode(0);//
      tableData.setMsg("成功");//执行成功返回“成功”
       tableData.setCount(queryall.getTotal());//设置总条数
           tableData.setData(queryall.getList());//设置当前数据
        return tableData;
    }
    /*
    增加支付记录
     */
    @OpLog(module = "支付增加数据",opType = "新增",key="payLog")
    @GetMapping("/add")
    @ResponseBody
    public Integer addTEST(PayLog payLog){
        //生成  订单 号
        String sn=SnowFlake.generateSN("YLRC","");//UID
        System.out.println(sn);
        payLog.setSn(sn);
        payLog.setTimetopay(new Date());
        payLog.setStatus(0);
        payLog.setCreatedtime(new Date());

        int save = payLogserviceimp.Insertdata(payLog);
        System.out.println(sn);
        PayLog bySN = payLogserviceimp.findBySN(sn);
        System.out.println(bySN);

        return bySN.getId();

    }
    /*
    发起退款页面
     */
    @RequestMapping("/refund")
    public String refund(Model model){
        return "refund";
    }
}
